package com.edu.marker.activities;

import java.util.ArrayList;

import com.edu.marker.R;
import com.edu.marker.pojo.QuestionInfo;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TipsQuestionAdapter extends BaseAdapter{
	private ArrayList<QuestionInfo> list = new ArrayList<QuestionInfo>();
	public LayoutInflater myLayoutInflater = null;
	private int mposition = -1;
	public Handler myHandler;
	
	public TipsQuestionAdapter(Context myContext,ArrayList<QuestionInfo> mylist,Handler handler){
		this.list = mylist;
		this.myHandler = handler;
		myLayoutInflater = (LayoutInflater)myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		if(convertView==null){
			convertView = myLayoutInflater.inflate(R.layout.tips_tihao_item, null);
			holder = new ViewHolder();
			holder.item_text = (TextView)convertView.findViewById(R.id.tips_exam_tihao_value);
			
			convertView.setTag(holder);
		}
		else{
			holder = (ViewHolder)convertView.getTag();
		}
		if(position==mposition){
			holder.item_text.setBackgroundResource(R.drawable.examnames_selector);
		}else{
			holder.item_text.setBackgroundColor(Color.WHITE);
		}
		
//		if(list.size()>0){
			final QuestionInfo mQuestionInfo = list.get(position);
			String name = "第"+(position+1)+"题      "+mQuestionInfo.questionName+"      共"+
					mQuestionInfo.questionCount+"题      已阅"+
					mQuestionInfo.questionIsCheckedCount+"题";
			holder.item_text.setText(name);
		
		convertView.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				mposition = position;
				Log.d("hsj", "第"+position+"行被选中了。");
				Message msg = myHandler.obtainMessage(3,mQuestionInfo.questionID);
				myHandler.sendMessage(msg);
			}
		});
//		}
		
		return convertView;
	}
	
	class ViewHolder{
		TextView item_text;
	}


}
